Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache repeated directory lookups for 12% speedup #356

Merged
merged 1 commit into from
Jan 10, 2023

Conversation

marvinhagemeister
Copy link
Contributor

Description

While profiling eslint tasks in various projects, I noticed that the polaris-related linting rules we have, take up a more time than necessary. This is most noticeable when when the project contains lots of files.

Screenshot 2023-01-09 at 19 03 01

The majority of the time in those two rules is spent in normalizeSource which traverses directories upwards to find the npm package root. This is perfectly fine if we haven't seen the file before, but unnecessarily expensive when we did resolve it once already. In the projects I tried this PR on, 95% of calls to normalizeSource are with a source file that we resolved already.

Therefore adding a simple caching mechanism bypasses the directory traversal and leads to about 12% faster linting times on the project I've tested it on.

Copy link
Member

@BPScott BPScott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great find!

Merge when you're happy, and I'll cut a release.

@marvinhagemeister marvinhagemeister merged commit 806bf87 into main Jan 10, 2023
@marvinhagemeister marvinhagemeister deleted the eslint-upwards-traverse branch January 10, 2023 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants